package blog.service.impl;

import blog.entity.Page;
import blog.mapper.PageMapper;
import blog.service.PageService;
import cn.hutool.http.HtmlUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PageServiceImpl implements PageService {
    @Resource
    private PageMapper pageMapper;
    @Override
    public List<Page> getList() {
        List<Page> pageList = pageMapper.getList();
        for (Page p:pageList){
           String pageContent = p.getPageContent();
           if(pageContent!=null)
           pageContent = HtmlUtil.cleanHtmlTag(pageContent);
           p.setPageContent(pageContent);
        }
        return pageList;
    }

    @Override
    public void deletePageById(Integer id) {
        pageMapper.deletePageById(id);
    }

    @Override
    public Page getPageById(Integer id) {
        return pageMapper.getPageById(id);
    }

    @Override
    public void updatePage(Page page) {
        pageMapper.updatePage(page);
    }

    @Override
    public void addPage(Page page) {
        pageMapper.addPage(page);
    }
}
